<!-- 个人中心 -->
<template>
	<view class="personal-wrap">
		<view class="top-info">

			<view class="left">
				<view class="cu-avatar xl round" :style="{ backgroundImage: ' url(' + shopDetail.shop_image + ')' }" style="width: 140rpx;height: 140rpx;">
				</view>

			</view>
			<view class="title">{{shopDetail.shop_name}}</view>


		</view>
		<view class="block"></view>
		<view class="order" style="position: relative;">

			<view style="display: flex;position: relative;">
				<view class="jin" style="font-size: 28rpx; flex: 2;">请输入账单金额</view>
				<view class="czje" style="position: absolute;right: 20rpx;font-weight: bold;flex: 1;display: flex;">
					￥<u-input type="digit" prefixIconStyle="￥" placeholder="0" :clearable="false" inputAlign="right" v-model="money"
					 :style="[{ width: monyWidth + 'px' }]" @input="changeWidth" @blur="orderPre"></u-input>
				</view>
			</view>
			<view class="br"></view>
			<view style="display: flex;position: relative;margin-top: 30rpx;">
				<view class="jin">米包</view>
				<view class="czje" style="position: absolute;right: 20rpx;">{{hongbao_money?'-￥'+hongbao_money:"无可用米包"}}</view>
			</view>
			<view class="br"></view>
			<view style="display: flex;position: relative;margin-top: 30rpx;">
				<view class="jin">代金券</view>
				<view style="width: 40vw;font-size: 28rpx;color: #999999;margin-left: 20rpx;line-height: 72rpx;"></view>
				<view class="czje" style="position: absolute;right: 20rpx;">{{daijinquan_money?'-￥'+daijinquan_money:"无可用代金券"}}</view>
			</view>
			<view class="br"></view>
			<view class="box1" style="align-items: center;justify-content: space-between;margin: 20rpx 0px!important;padding: 10px 10px;">
				<view style="display: flex;align-items: center;flex: .6;">
					<!-- <u-icon name="error-circle-fill" color="#fc5451" size="25px"></u-icon> -->
				</view>
			<!-- 	<view v-if="daijinquan_money <=0" style="flex: 5;color: #FC5351;font-size: 12px;width: 420rpx;display: flex; align-items: center;"
				>每次抵扣的金额不得高于代金券赠送时的50%</view> -->
				<view v-if="daijinquan_money > 0" style="flex: 5;color: #FC5351;font-size: 12px;width: 420rpx;display: flex; align-items: center;"
				>本单代金券最多可抵扣{{daijinquan_money?daijinquan_money:0}}元</view>
				<view>
					<view style="padding: 2px 8px;;text-align:center;border:1px solid #FC5351;border-radius: 13px 13px 13px 13px;height: 22px;font-size: 10px;font-weight: 500;color: #FC5351;line-height: 12px;display: flex;justify-content: center;align-items: center;"
					@click="toRecharge">去充值</view>
				</view>
			</view>
			<view style="position: relative;">
				<view style="display: flex;justify-content: flex-end; line-height: 50px;align-items: center;">
					<view style="font-size: 16px;line-height: 60rpx;">实际支付:</view>
					<view style="font-size: 22px;color: #FC5351;margin-left: 5rpx;">￥{{payMoney}}</view>
				</view>
			</view>
		</view>
		<!-- <view v-if="payMoney==0" style=" display: flex;justify-content: center;align-items: center; ">
			<view class="zhifu">立即支付</view>
		</view> -->
		<view  style=" display: flex;justify-content: center;align-items: center; " @click="topay">
			<view class="zhifu" style="background: #FD5958;">立即支付</view>
		</view>

	</view>
</template>

<script>
	import {
		mapMutations,
		mapActions,
		mapState,
		mapGetters
	} from "vuex";
	export default {
		data() {
			return {
				monyWidth: "40",
				money: "",
				payMoney: 0,
				value: '',
				swiperList: [{
					id: 0,
					type: 'image',
					text: '100元',
				}, {
					id: 1,
					type: 'image',
					text: '200元',
				}, {
					id: 2,
					type: 'image',
					text: '300元',
				}, {
					id: 3,
					type: 'image',
					text: '400元',
				}, {
					id: 3,
					type: 'image',
					text: '500元',
				}, {
					id: 3,
					type: 'image',
					text: '600元',
				}],
				cardCur: -1,
				shopDetail: null,
				hongbao_money: null,
				daijinquan_money: null
			};
		},
		onLoad(options) {
			console.log(options);
			this.store_shop_id = options.id
			this.init();
			// this.orderPre();
		},
		methods: {
			changeWidth(event) {
				console.log("=========change", event.length)
				if (event.length == 0) {
					this.monyWidth = 40;
				} else {
					this.monyWidth = event.length * 10;
				}
			},
			async change(event) {
				uni.showLoading({
					title: '计算中...'
				})
				console.log("=========change", event)
				var daijinquan_money = this.daijinquan_money
				var hongbao_money = this.hongbao_money
				// if (daijinquan_money > (event / 2)) {
				// 	daijinquan_money = event / 2;
				// }
				var total = event - daijinquan_money
				total = total - hongbao_money;
				console.log(total);
				if (parseFloat(total) <= 0) {
					total = 0.1
					console.log(total);
				}
				console.log(total);
				this.payMoney = total
				uni.hideLoading()
			},
			async init() {
				console.log("=========shopDetail")
				var that = this;
				that.$https('category.shopDetail', {
						token: uni.getStorageSync("token"),
						store_shop_id: this.store_shop_id
					})
					.then(res => {
						if (res.code === 1) {
							that.shopDetail = res.data;
						}
					});
			},
			async orderPre() {
				if(this.money.length==0){
					uni.showToast({
						title:"请输入正确的金额",
						icon:"none"
					})
					return
				}
				uni.showLoading({
					title: '加载中'
				})
				console.log("=========orderPre")
				var that = this;
				that.$https('category.orderPre', {
						token: uni.getStorageSync("token"),
						amount:this.money,
						store_shop_id:this.store_shop_id
					})
					.then(res => {
						uni.hideLoading()
						if (res.code === 1) {
							that.hongbao_money = res.data.hongbao_money;
							that.daijinquan_money = res.data.daijinquan_money;
							that.change(that.money)
						}
					});
			},
			topay() {
				console.log("=========orderPay")
				var that = this;
				if(this.money==0){
					uni.showToast({
						title: "支付金额不能为0元",
						icon: "none",
						mask: true,
						duration: 2000
					})
					return;
				}
				that.$https('category.orderPay', {
						token: uni.getStorageSync("token"),
						amount: this.money,
						hongbao_money: this.hongbao_money,
						daijin_money: this.daijinquan_money,
						cash_money: this.payMoney,
						store_shop_id: this.store_shop_id,
					})
					.then(res => {
						console.log("***********orderPay", res);
						if (res.code === 1) {
							uni.showToast({
								title: "支付成功",
								icon: "none",
								mask: true,
								duration: 2000
							})
							setTimeout(function() {
								var param = {
									token: uni.getStorageSync("token"),
									amount: that.money,
									hongbao_money: that.hongbao_money,
									daijin_money: that.daijinquan_money,
									zengsong_money: res.data.order.zengsong_money,
									cash_money: that.payMoney,
									store_shop_id: that.store_shop_id,
									order_id: res.data.order_id,
									shop: res.data.shop
								}
								uni.setStorageSync("paySuccess", param)
								uni.redirectTo({
									url: '/pages/index/category/paySuccess'
								})
							}, 2000);
						}
					});

			},
			clickItem(index) {
				this.cardCur = index;
			},
			hideKeyboard(e) {
				console.log('e', e)
				this.value = e.detail.value
				console.log('value', this.value)
			},
			toRecharge() {
				uni.navigateTo({
					url: '/pages/index/recharge'
				})
			}
		},
	}
</script>

<style lang="scss" scoped>
	* {
		box-sizing: border-box;
		margin: 0;
		padding: 0;
	}

	.personal-wrap {
		padding-bottom: 100rpx;
		// position: relative;
		height: 100vh;
		overflow-y: auto;

		.top-info {
			height: 520rpx;
			width: 750rpx;
			// background: #fe6766;
			// background-image:url('https://duomi.bigchun.com/images/beijing.png');
			background: url();
			background-size: cover;

			.left {
				justify-content: center;
				display: flex;
				color: #fff;
				padding-top: 120rpx;
			}




		}

		.order {
			width: 690rpx;
			// height: 570rpx;
			padding: 20rpx;
			background-color: #fff;
			margin: auto;
			border-radius: 20rpx;
			margin-top: -80rpx;
			box-shadow: inset 0px 18px 4px -10px #ff878785;
		}

		.shu {
			width: 690rpx;
			height: 108rpx;
			padding: 20rpx;
			background-color: #fff;
			border-radius: 16rpx 16rpx 16rpx 16rpx;
			// margin-top: 44rpx;
			// margin-left: 24rpx;
			// margin-right: 24rpx;
			margin: 44rpx auto;
		}

		.title {
			font-size: 32rpx;
			font-family: PingFang SC-Bold, PingFang SC;
			font-weight: bold;
			color: #FFFFFF;
			line-height: 19px;
			display: flex;
			justify-content: center;
			margin-top: 40rpx;
		}

		.jin {
			font-size: 28rpx;
			font-weight: 500;
			line-height: 72rpx;
			margin-left: 24rpx;
		}

		.czje {
			font-size: 28rpx;
			font-family: PingFang SC-Medium, PingFang SC;
			// font-weight: 500;
			color: #333333;
			line-height: 68rpx;
			margin-left: 10rpx;
		}

		.indication {
			z-index: 9999;
			// width: 300px;
			// width: 325px;
			// height: 36rpx;
			position: absolute;
			display: flex;
			flex-wrap: wrap;
			justify-content: space-between;
			// margin-left: 12px;
			margin-right: 24rpx;
		}

		.spot {
			color: #666666;
			opacity: 1;
			right: 0;
			position: relative;
			text-align: center;
			font-size: 28rpx;
			font-weight: 600;
			width: 192rpx;
			height: 112rpx;
			background: #F6F6F6;
			border-radius: 20rpx 20rpx 20rpx 20rpx;
			opacity: 1;
			margin-top: 20rpx;
			display: flex;
			justify-content: center;
			align-items: center;
		}

		.spot.active {
			// color: #FFFFFF;
			// opacity: 1;
			// background-image: linear-gradient(45deg, #0081ff, #1cbbb4);
			background: #FFEDED;
			color: #FC5351;
			border-radius: 16rpx 16rpx 16rpx 16rpx;
			border: 1px solid #FC5351;
		}

		.yuan {
			position: absolute;
			right: 20rpx;
			font-weight: 500;
			color: #666666;
			line-height: 80rpx;
			font-size: 40rpx;
		}

		.in input {
			text-align: right;
			color: #FC5351;
		}

		.tips {
			width: 686rpx;
			// height: 180rpx;
			height: 168rpx;
			background: #F9E8E0;
			border-radius: 16rpx 16rpx 16rpx 16rpx;
			opacity: 1;
			margin-top: 20rpx;
			margin-left: 24rpx;
			margin-right: 24rpx;
			// padding-top: 30rpx;
			// padding-left: 24rpx;
			// padding-right: 24rpx;
			padding: 24rpx 24rpx 24rpx 24rpx;
		}

		.content {
			font-size: 26rpx;
			font-family: PingFang SC-Regular, PingFang SC;
			font-weight: 400;
			color: #FF6121;
			line-height: 40rpx;
		}

		.di {
			width: 750rpx;
			height: 150rpx;
			background: #FFFFFF;
			position: absolute;
			bottom: 0px;

		}

		.btn2 {
			width: 196rpx;
			height: 72rpx;
			background: linear-gradient(90deg, #FC5351 0%, #FF6E6D 100%);
			border-radius: 74rpx 74rpx 74rpx 74rpx;
			opacity: 1;
			position: absolute;
			right: 32rpx;
			top: 29rpx;
			color: #FFFFFF;
			font-size: 28rpx;
			text-align: center;
			display: flex;
			justify-content: center;
			align-items: center;
		}

		.dz {
			font-size: 28rpx;
			font-family: PingFang SC-Medium, PingFang SC;
			font-weight: 500;
			color: #333333;
			line-height: 42rpx;
		}

		.gwjqian {
			font-size: 36rpx;
			font-family: PingFang SC-Medium, PingFang SC;
			font-weight: 500;
			color: #FC5351;
			line-height: 42rpx;
		}

		.gwj {
			font-size: 24rpx;
			font-family: PingFang SC-Medium, PingFang SC;
			font-weight: 500;
			color: #FC5351;
			line-height: 42rpx;
			margin-left: 4rpx;
		}

		.djjqian {
			font-size: 36rpx;
			font-family: PingFang SC-Medium, PingFang SC;
			font-weight: 500;
			color: #FC5351;
			line-height: 42rpx;
			margin-left: 4rpx;
		}

		.djj {
			font-size: 24rpx;
			font-family: PingFang SC-Medium, PingFang SC;
			font-weight: 500;
			color: #FC5351;
			line-height: 42rpx;
		}

		.block {
			width: 702rpx;
			height: 28rpx;
			background: #ED4948;
			border-radius: 20rpx 20rpx 20rpx 20rpx;
			// position: absolute;
			// top: 426rpx;
			left: 24rpx;
			// opacity: 0.2;
			// z-index: 99;
			top: -64rpx;
			position: relative;
		}
	}

	.br {
		margin-left: 24rpx;
		margin-right: 24rpx;
		border: 1px solid #F3F3F3;
	}

	.box1 {
		background: #FFE9E9;
		border-radius: 8px 8px 8px 8px;
		opacity: 1;
		margin: 20rpx auto;
		display: flex;
	}

	.zhifu {
		width: 680rpx;
		height: 80rpx;
		border-radius: 40rpx;
		background: #D2D2D2;
		display: flex;
		justify-content: center;
		align-items: center;
		position: absolute;
		bottom: 25px;
		margin: 0 auto;
		color: white;
	}

	input {
		width: 120rpx !important;
	}

	.u-input--border {
		border: transparent;
	}
</style>
